1. Field of the Present Invention
The present invention generally relates to computer graphics and more particularly to a circuit that generates normalized vectors (unit vectors) that are specified by a graphics interface.
2. History of Related Art
Graphics display subsystems are almost universally encountered in microprocessor based computer systems to facilitate a variety of graphics tasks and applications including computer-assisted drafting, architectural design, simulation trainers for aircraft and other vehicles, molecular modeling, virtual reality applications, and video games. Graphics processors, graphics adapters, and a variety of similarly designed computer products provide specialized hardware to speed the execution of graphics instructions and rendering of graphic images. These processors and adapters typically include, for example, circuitry optimized for translating, rotating, and scaling 3D graphic images. In a typical application, a graphical image that is displayed on a display terminal or other output device is composed of one or more graphic primitives. For purposes of this disclosure, a graphic primitive may be thought of as one or more points, lines, or polygons that are associated with one another, such as by being connected to one another. Typically, the displayed image is generated by creating one or more graphic primitives, assigning various attributes to the graphic primitives, defining a viewing point and a viewing volume, determining which of the graphic primitives are within the defined viewing volume, and rendering those graphic primitives as they would appear from the viewing point. This process can require a tremendous amount of computing power to keep pace with the ever increasingly complex graphics applications that are commercially available. Accordingly, designers of graphics systems and graphics applications are continuously seeking cost effective means for improving the efficiency at which graphic images are rendered and displayed.
Typically a software application program generates a 3D graphics scene, and provides the scene, along with lighting attributes, to an application programming interface (API) such as the OpenGL(copyright) API developed by Silicon Graphics, Inc. Complete documentation of OpenGL(copyright) is available in M. Woo et al., OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 1.2 (Addison Wesley Longman, Inc. 1999) and D. Schreiner, OpenGL Reference Manual, Third Edition: The Official Reference Document to OpenGL, Version 1.2 (Addison Wesley Longman, Inc. 1999), both of which are incorporated by reference herein.
A 3D graphics scene typically includes of a number of polygons that are delimited by sets of vertices. The vertices are combined to form larger primitives, such as triangles or other polygons. The triangles (or polygons) are combined to form surfaces, and the surfaces are combined to form objects. Each vertex is associated with a set of attributes. Vertex attributes may include a position, including three Cartesian coordinates x, y, and z, a material color, which describes the color of the object to which the vertex belongs, and a normal vector, which describes the direction to which the surface is facing at the vertex. Each vertex may also be associated with texture coordinates and/or an alpha (transparency) value. In addition, the scene itself may be associated with a set of attributes including, as examples, an ambient color that typically describes the amount of ambient light and one or more individual light sources. Each light source has a number of properties associated with it, including a direction, an ambient color, a diffuse color, and a specular color.
Rendering is employed within the graphics system to create two-dimensional image projections of a 3D graphics scene for display on a monitor or other display device. Typically, rendering includes processing geometric primitives (e.g., points, lines, and polygons) by performing one or more of the following operations as needed: transformation, clipping, culling, lighting, fog calculation, and texture coordinate generation. Rendering further includes processing the primitives to determine component pixel values for the display device, a process often referred to specifically as rasterization.
The OpenGL(copyright) API and other API""s such as the DirectX(copyright) API from Microsoft define the allowed vertex and scene attributes and the equations used to determine attribute values. In a conventional graphics adapter, the calculations specified by a particular API are implemented in software. It will be appreciated that software calculations can adversely affect the performance of the graphics adapter, especially if the equations require complex, floating point calculations. It would therefore be desirable to implement, to the extent feasible, some or all of the calculations specified by a particular graphics API in dedicated hardware circuitry. Moreover, it would be desirable if the implemented solution balanced improved performance against cost by optimizing the hardware design to account for such factors as, the frequency with which the particular function or equation is invoked and the speed required of the particular equation.
Normalization of a vector or vertex is a calculation that is used extensively within 3D APIs for lighting and texture coordinate generation. Lighting uses units vectors to generate vertex color data. Texture generation employs normalization to generate spherical coordinates. The components of a unit normal vector Nxe2x80x2 are calculated as follows:
Nx40 =Nx/(Nx2+Ny2+Nz2)0.5
Ny40 =Ny/(Nx2+Ny2+Nz2)0.5
Nz40 =Nz/(Nx2+Ny2+Nz2)0.5
where Nx, Ny, and Nz define a normal vector N. Similarly, the components Exxe2x80x2, Eyxe2x80x2, and Ezxe2x80x2 of a unit eye vector Exe2x80x2 pointing from the origin to a vertex (in eye coordinates) are calculated as follows:
Exxe2x80x2=Ex/(Ex2+Ey2+Ez2)0.5
Eyxe2x80x2=Ey/(Ex2+Ey2+Ez2)0.5
Ezxe2x80x2=Ez/(Ex2+Ey2+Ez2)0.5
where Ex, Ey, and Ez are the eye coordinates of the vertex.
The graphics adapter should have the ability to calculate these two sets of three equations independent of each other. In other words, the graphics adapter should be able to calculate the Nxe2x80x2 and Exe2x80x2 values either independently or in parallel. Since each equation requires three floating point multipliers and two floating point adders, an implementation could include 18 floating point multipliers and 12 floating point adders to handle all six equations in parallel. The number of resources could be reduced if the same multipliers and adders are reused in each set (i.e., all Nxe2x80x2 calculations as well as all Exe2x80x2 calculations use the same floating point units). Such an implementation, however, would still require three floating point multipliers and two adders for the Nxe2x80x2 calculations and the same for the Exe2x80x2 calculations, thus requiring a total of six floating point multipliers and four floating point adders. Because each floating point unit is a relatively expensive circuit to implement, even the fewer resources required of the shared implementation includes an undesirably large number of units. It would, therefore, be highly desirable to introduce a graphics adapter with a dedicated normalization unit that required fewer floating point resources and performed without a significant performance penalty over more costly implementations.
A normalization circuit suitable for use in a graphics adapter is disclosed. The circuit is configured to receive vertex data and includes a set of multiplexer circuits, a set of functional units, and a control circuit. The outputs of the set of multiplexer circuits provide inputs to the set of function units and the control circuit is configured to control the select inputs of the set of multiplexer units to calculate a unit normal vector and a unit eye vector from the received vertex data. The set of functional units may include a pair of floating point multipliers and a floating point adder. The inputs of the first floating point multiplier may be connected to outputs of first and second mulitplexers such that the first multiplier is enabled to generate square values for x, y, and z components of the vertex data. The inputs of the floating point adder may be connected to outputs of third and fourth multiplexers, wherein the floating point adders is enabled to generate a sum of squares values. The output of the floating point adder may be coupled to the input of an inverse square circuit. A first input to the second floating point multiplier may be connected to a fifth multiplexer circuit and a second input to the second floating point multiplier may be coupled to the output of the inverse square root circuit such that the second floating point multiplier is enabled to generate x, y, and z components of the unit normal vector and the unit eye vector.